def call(Map map){
    pipeline {
        agent {
            label 'java'
        }

        tools {
            jdk 'jdk8'
            maven 'maven3.8.9'
            nodejs 'node14'
            git 'git'
        }

        environment {
            //前端
            FRONT_NAME = "ruoyi-ui"
            FRONT_IMAGE = "swr.cn-north-4.myhuaweicloud.com/btj/${env.JOB_NAME}:${env.BUILD_NUMBER}"

            FRONT_GITURL = map.get('git')
            ANSIBLE_GITURL = "git@gitee.com:bsm2023/ruoyi-playbook.git"
        }

        parameters {
            choice(name: 'BUILD_ENV', choices: 'dev\ntest\nuat', description: '请选择部署环境:')
            gitParameter(branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BUILD_BRANCH', type: 'PT_BRANCH', description: '请选择分支:', useRepository: "${env.BACK_GITURL}")
        }

        stages {
            stage('1.2拉取前端代码') {
                steps {
                    cleanWs()
                    git branch: 'master', credentialsId: 'ssh', url: "${env.FRONT_GITURL}"
                }
            }

            stage('2.2编译前端') {
                steps {
                    script{
                        docker.image('swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/library/node:14-alpine').inside() {
                            sh "npm config set registry https://registry.npmmirror.com/"
                            sh "npm install"
                            sh "npm run build:prod"
                        }
                    }

                }
            }

            stage('3.2构建前端镜像') {
                steps {
                    script {
                        configFileProvider([configFile(fileId: 'ruoyi-ui-dockerfile', variable: 'dockerfile')]) {
                            docker.withRegistry("https://swr.cn-north-4.myhuaweicloud.com", "huaweiyun") {
                                def app = docker.build("${env.FRONT_IMAGE}", ". -f ${dockerfile}")
                                app.push()
                            }
                        }
                    }

                }
            }
        }
    }

}